<?php

namespace app\admin\controller;
use app\app\model\AppVersionModel;
use app\BaseController;
use app\Request;
use app\app\model\RandModel;

class AppVersion extends BaseController
{
    public function list()
    {
        $res = AppVersionModel::where("1=1")->order('version desc')->select();
        $this->success('success', $res);
    }

    public function add(Request $request)
    {
        $data = $request->param();
        $data['id'] = RandModel::randId();
        $data['update_time'] = date('Y-m-d H:i:s', time());
        AppVersionModel::create($data);
        $this->success('success');
    }

    public function latest()
    {
        $res = AppVersionModel::field('version, download_link')->order('version','desc')->find();
        $res['download_link'] = str_replace('\\', '/', $res['download_link']);
        $this->success('success',$res);
    }
}
